package com.liao.myblog.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.liao.myblog.dao.CommentMapper;
import com.liao.myblog.pojo.Comment;
import com.liao.myblog.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommentServiceImpl implements CommentService {
    @Autowired
    private CommentMapper commentMapper;

    @Override
    public List<Comment> queryCommentByBlogId(int blogId) {
        return commentMapper.queryCommentByBlogId(blogId);
    }

    @Override
    public int checkComment(int[] ids) {
        return commentMapper.checkComment(ids);
    }

    @Override
    public int deleteComment(int[] ids) {
        return commentMapper.deleteComment(ids);
    }

    @Override
    public int replyComment(Comment comment) {
        return commentMapper.replyComment(comment);
    }

    @Override
    public PageInfo<Comment> queryCommentList(int limit, int page) {
        System.out.println("limit="+limit+"page="+page);
        PageHelper.startPage(page,limit);
        List<Comment> comments = commentMapper.queryCommentList();
        return new PageInfo<>(comments);
    }

    @Override
    public int queryCommentCountByBlogId(int blogId) {
        return commentMapper.queryCommentCountByBlogId(blogId);
    }

    @Override
    public int queryCommentCount() {
        return commentMapper.queryCommentCount();
    }

    @Override
    public List<Comment> queryCommentByPage(int limit, int offset, int id) {
        return commentMapper.queryCommentByPage(limit, offset * limit, id);
    }

    @Override
    public int addComment(Comment comment) {
        return commentMapper.addComment(comment);
    }
}
